#include	"../include/Commandline.h"

Commandline::Commandline(int argc, char * argv[]) {
	_parsed.clear();

	for (int i = 0; i < argc; ++i) {
		if (!argv[i] || !argv[i][0]) continue;
		std::string param(argv[i]);
		size_t pos = param.find_first_of('=');
		size_t len = param.length();
		if (pos == std::string::npos) {
			_parsed[param] = "";
		} else if (pos == 0) {
			continue;
		} else if (pos == len - 1) {
			_parsed[param.substr(0, len - 1)] = "";
		} else {
			_parsed[param.substr(0, pos)] = param.substr(pos + 1, len - 1 - pos);
		}
	}
}

bool Commandline::Has(const char * key) const {
	return _parsed.find(key) != _parsed.end();
}